/**
 * 上传图片
 * @property {Number} type 1图片  2视频 
 * 调用方法： this.$mUpload(1, obj, res => {console.log(res)})
 */

import indexConfig from '@/config/index.config.js'
import http from '@/utils/request.js'
import {
	uploadImg,
	uploadFile
} from '@/api/product.js'

export const upload = (type, file, callback) => {
	if (type == 1) {
		uni.showLoading({
			title: '上传中',
			mask: true
		})
		uni.uploadFile({
			url: indexConfig.baseUrl + uploadImg, //仅为示例，非真实的接口地址
			filePath: file.url,
			name: 'img',
			success: res => {
				callback(res);
				uni.hideLoading()
			},
			fail: err => {
				console.log(err)
			}
		})
	} else {
		uni.showLoading({
			title: '上传中',
			mask: true
		})
		// if (file.size <= 20971520) {
		uni.uploadFile({
			url: indexConfig.baseUrl + uploadFile, //仅为示例，非真实的接口地址
			filePath: file.url,
			name: 'file',
			success: res => {
				callback(res);
				uni.hideLoading()
			},
			fail: err => {
				console.log(err)
			}
		})
		// } else {
		// 	uni.showToast({
		// 		title: '上传视频不能超出20M大小',
		// 		mask: true,
		// 		duration: 1000
		// 	})
		// }
	}
}

module.exports = upload